{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 2 python进阶基础作业"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.1有四个数字：1、2、3、4，能组成多少个互不相同且无重复数字的三位数？各是多少？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123 124 132 134 142 143 213 214 231 234 241 243 312 314 321 324 341 342 412 413 421 423 431 432 \n",
      "共24种组合\n"
     ]
    }
   ],
   "source": [
    "counter=0\n",
    "for i in range(1,5):\n",
    "    for j in range(1,5):\n",
    "        for k in range(1,5):\n",
    "            if i !=j and j !=k and k !=i:\n",
    "                print(\"{}{}{}\".format(i,j,k),end=\" \")\n",
    "                counter +=1\n",
    "print(\"\")\n",
    "print(\"共{}种组合\".format(counter))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.2  a=[1, 2, 3, 4, 5], a[::2]=?, a[-2:] = ?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 3, 5]\n",
      "[4, 5]\n"
     ]
    }
   ],
   "source": [
    "a = [1,2,3,4,5]\n",
    "print(a[::2])\n",
    "print(a[-2:])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.3 使用filter过滤[1,2,7,12,45,56,66]中的奇数，最后输出[2,12,56,66]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 12, 56, 66]\n"
     ]
    }
   ],
   "source": [
    "\n",
    "newlist = filter(lambda x:x%2==0,[1,2,7,12,45,56,66])\n",
    "print(list(newlist))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
